package com.itheima.thread.utils.semaphore.demo01;

import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

public class SemaphoreThread implements Runnable {

    private Semaphore semaphore = new Semaphore(2);

    @Override
    public void run() {
        try {
            semaphore.acquire();
            System.out.println(Thread.currentThread().getName() + "获取到了许可证...");
            TimeUnit.SECONDS.sleep(3);
            System.out.println(Thread.currentThread().getName() + "释放了许可证...");
            semaphore.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
